//
//  GuideView.swift
//  Wmsmobile
//
//  Created by wangshuning on 16/9/9.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class GuideView: UIView {
    
    var defaultImage:UIImage?
    var imageView:UIImageView?
    var desLabel:UILabel?
    var visionLabel:UILabel?
    
    convenience init(frame: CGRect, defaultImage:UIImage){
        self.init()
        self.frame = CGRect(x: 0, y: 0, width: KscreenWidth, height: KscreenHeight)
        self.defaultImage = defaultImage
        self.layout()
    }
    func layout() {
        
        // 获取版本号
        let infoDictionary = Bundle.main.infoDictionary
        let appCurVersionNum = infoDictionary!["CFBundleVersion"]
        self.desLabel = UILabel.init(frame: CGRect(x: 0, y: KscreenHeight-70, width: KscreenWidth, height: 32))
        self.desLabel!.text = "上海海鼎信息工程股份有限公司V\(appCurVersionNum!)版本"
        self.desLabel?.textAlignment = NSTextAlignment.center
        self.desLabel?.font = UIFont.systemFont(ofSize: 12)
        self.desLabel?.textColor = UIColor.white
        
        self.visionLabel = UILabel.init(frame: CGRect(x: 0, y: KscreenHeight-90, width: KscreenWidth, height: 32))
        self.visionLabel!.text = ""
        self.visionLabel?.font = UIFont.systemFont(ofSize: 15)
        self.visionLabel?.textAlignment = NSTextAlignment.center
        self.visionLabel?.textColor = UIColor.white

        
        self.imageView = UIImageView.init(frame: self.bounds)
        self.imageView?.contentMode = UIViewContentMode.scaleToFill
        self.imageView?.alpha = 1.0
        self.addSubview(self.imageView!)
//        self.addSubview(self.visionLabel!)
//        self.addSubview(self.desLabel!)
        self.imageView?.image = self.defaultImage
        self.startAnimation(3.0)
    }
    
    func startAnimation(_ duration:TimeInterval) {
        self.imageView?.transform = CGAffineTransform.identity
        UIView.animate(withDuration: duration, delay: 3, options: UIViewAnimationOptions(), animations: {
//            self.imageView!.transform = CGAffineTransformMakeScale(1.3,1.3);
//            self.imageView!.alpha = 1;
            }) { (finished) in
                UIView.animate(withDuration: duration+2, animations: {
//                    self.imageView!.transform = CGAffineTransformIdentity
                    }, completion: { (finished) in
                        self.removeFromSuperview()
                })
        }
    }

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */

}
